<template>
    <div>
        1
    </div>
</template>

<script lang="ts">
export default { name: '' }
</script>

<script lang="ts" setup>
import { getCurrentInstance, ComponentInternalInstance, reactive, ref, nextTick, onMounted, useAttrs, useSlots } from 'vue'
import axios from 'axios'

// const slots = useSlots()
// const attrs = useAttrs()
// const emits = defineEmits()
const { proxy }:any = getCurrentInstance() as ComponentInternalInstance

const state = reactive({

})

onMounted(() => {
    const url = 'http://101.132.163.3:9000/inap/1666678628842-121?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20221026%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20221026T030215Z&X-Amz-Expires=172800&X-Amz-SignedHeaders=host&X-Amz-Signature=bc3675883c1e2a2060dd2db466ffa0994d827a95251b5f0b35905f2207e06a75'
    axios.get(url, { responseType: 'blob' }).then((r: any) => {
        console.log(r.data)
        const fileRead = new FileReader()
        fileRead.readAsDataURL(r.data)
        fileRead.onload = (r) => {
            console.log(r)
        }
    }).catch((e: any) => {
        console.warn(e)
    })
    const xhr = new XMLHttpRequest()
    xhr.open('GET', url, true) // 也可以使用POST方式，根据接口
    // xhr.setRequestHeader('Authorization', getToken()) 添加token
    xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8')
    xhr.responseType = 'blob' // 返回类型blob
    // 定义请求完成的处理函数，请求前也可以增加加载框/禁用下载按钮逻辑
    xhr.onload = function () {
        console.log(this.response)

        // 请求完成
        // if (this.status === 200) {
        //     if (this.response.type === 'application/json') {
        //         console.warn(this.response)

        //         return
        //     }
        //     // 返回200
        //     const reader = new FileReader()
        //     reader.readAsDataURL(this.response) // 转换为base64，可以直接放入a表情href
        //     reader.onload = function (e) {
        //         // const filename = 'a'
        //         // // 转换完成，创建一个a标签用于下载
        //         // const downEl = document.createElement('a')
        //         // downEl.download = filename
        //         // downEl.href = e.target.result
        //         // document.body.appendChild(downEl) // 修复firefox中无法触发click
        //         // downEl.click()
        //         // document.body.removeChild(downEl)
        //     }
        //     console.log(this.response)
        // } else {
        //     console.warn(this.response)
        // }
    }
    // 发送ajax请求
    xhr.send()
})

// defineExpose({

// })
</script>
<style lang="scss" scoped>

</style>
